import time
import json
import get_cov_data


def read_json():
    with open('JsonData.json', "r",encoding='utf-8') as f:
        row_data = json.load(f)
    return row_data

def get_l1_data():
    data = read_json()['component'][0]['trend']
    l1_time = data["updateDate"]
    # print(l1_time)
    find = data['list'][10]['data']
    died = data['list'][12]['data']
    # print(died)
    # print(find)
    return [l1_time, find, died]

def get_l2_data():
    label_list = ['mapLastUpdatedTime', 'province', 'city', 'address', 'level']
    data = read_json()['component'][0]
    c2_data = []
    last_time = data['mapLastUpdatedTime']
    for province in data['caseList']:
        province_name = province['area']
        for city in province['subList']:
            city_name = city['city']
            if city['dangerousAreas']['subList']:
                for adress in city['dangerousAreas']['subList']:
                    temp = [last_time,province_name,city_name]
                    if len(adress['area'])>15:
                        continue
                    else:
                        temp.append(adress['area'])
                        temp.append((adress['level']))
                        c2_data.append(temp)
    return c2_data

def get_r2_data():
    ignore_list = ['待确认人员','境外输入','待确认','外来返川人员']
    data = read_json()['component'][0]['caseList']
    r2_data = []
    for province in data:
        for city in province['subList']:
            if city['city'] in ignore_list:
                continue
            else:
                temp = {'name':city['city'],'value':city['curConfirm']}
                r2_data.append(temp)
    return r2_data


def get_r1_data():
    data = read_json()['component'][0]['topOverseasInput']
    # [{name,value}]
    pro_name = []
    pro_count = []
    for item in data:
        pro_name.insert(0, item['name'])
        pro_count.insert(0, item['value'])
    pro_count = pro_count[1:]
    pro_name = pro_name[1:]
    # print([pro_name, pro_count])
    return [pro_name, pro_count]

def get_c1_data():
    label_list = ['confirmed','overseasInput','cured','died','curConfirm','curOverseasInput','curLocalConfirm','asymptomaticLocal']
    data = read_json()['component'][0]['summaryDataIn']
    c1_data = []
    for label in label_list:
        c1_data.append(data[label])
    return c1_data

def get_c2_data():
    data = read_json()['component'][0]['caseList']
    total_province_list = []
    for province in data:
        temp = dict()
        temp['name'] = province['area']
        temp['value'] = province['curConfirm']
        total_province_list.append(temp)
    return total_province_list


if __name__ == '__main__':
    print(get_r2_data())